<%@page import="com.neiquan.backstage.pub.bsc.dao.po.Lease"%>
<%@page import="com.neiquan.backstage.resourec_manage.ResourecLeaseService"%>
<%@page import="com.neiquan.backstage.pub.bsc.dao.po.Entrepreneur"%>
<%@page import="com.neiquan.backstage.resourec_manage.EntrepreneurService"%>
<%@page import="com.neiquan.backstage.resourec_manage.ResourecStationService"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@page import="com.neiquan.backstage.common.util.SpringContextUtils"%>
<%@page import="com.neiquan.backstage.pub.bsc.dao.po.User"%>
<%@page import="com.neiquan.backstage.common.util.Sessions"%>
<%@page import="java.util.List"%>
<%@page import="com.neiquan.backstage.common.CommonService"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
ApplicationContext appCtx =  SpringContextUtils.getApplicationContext();
ResourecStationService resourecStationService = appCtx.getBean(ResourecStationService.class);
ResourecLeaseService resourecLeaseService= appCtx.getBean(ResourecLeaseService.class);
EntrepreneurService entrepreneurService=appCtx.getBean(EntrepreneurService.class);
User user = (User) Sessions.getLoginedUser(session);


%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<meta charset="UTF-8">
	<title>工位管理</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=1.0" />
	<meta name="apple-mobile-web-app-capable" content="yes" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<link rel="stylesheet" href="css/base.css" />
	<link rel="stylesheet" href="css/main.css" />
</head>
	<body bgcolor="#ededed">
		<section class="common_bg addr_wrap">
			<section  class="relative tc area-wrap">
				<label>我的工位</label>
			</section> 
			<section class="line addr_line"></section>
			<!-- 没有工位的大模块 -->
			<section id="chunkNothing" class="common_bg mt">
						<section class="perfect pd">
							<p class="form-inpt-p">
								<label>当前暂无工位信息</label>
							</p>
						</section>
				<section class="addr_sub pd">
					<input type="button" class="btn rent_submmit" onClick="gotoApplyPage()" value="申请工位">
				</section>		
			</section>
			<!-- 有工位大模块 -->
			<section id="chunkSomething" class="mt">
				<section id="table2">
				<table id='table1' class="addr_table" cellpadding="0" cellspacing="0">
				</table>
				<p class="tc">
					<!--<span class="diamond">已选择的工位</span>
					<span id="changeStation" class="diamond diamond_left">调整后的工位</span>
					<span class="diamond diamond_right">已被占用</span>-->
					<p class="diamond ml10">已选择的工位</p>
					<p id="changeStation" class="diamond diamond_left">调整后的工位</p>
					<p class="diamond diamond_right">已被占用</p>
				</p>
				</section>
			<!-- 有工位并且一起都是正常态 -->
				<section id="chunkPass">
					<section class="addr_sub pd">
						<p class="form-inpt-p">
							<span>租用结束时间</span>
							<input  name="endTime" class="inpt endTime" required  type="text"  readonly="readonly" />
						</p>
						<input type="button" class="btn rent_submmit1" onClick="gotoNewlyApplyPage()" value="申请">
						<input type="button" class="btn rent_submmit1" onClick="gotoChangeApplyPage()" value="更换">
					</section>
				</section>	
			<!-- 有工位wait -->
				<section id="chunkWait">
						<section class="common_bg">
					<section class="perfect pd">
						<p class="form-inpt-p">
							<label >租金</label>
							<input  type="text"  name="sumRental" class="inpt sumRental"  required type="text" readonly="readonly" />(元/月)
						</p>
						<p class="form-inpt-p">
							<label >租用开始时间</label>
      						<input type="text" name="stratTime" required class="inpt stratTime"  readonly="readonly"/>
						</p>
						<p class="form-inpt-p">
							<label  >租长时间(个月)</label>
      						<input type="text" name="monthNumber"  required class="inpt monthNumber"  readonly="readonly"/>
						</p>
						<p class="form-inpt-p">
							<label  >租用结束时间</label>
							<input name="endTime" class="inpt endTime" required  type="text"  readonly="readonly" />
						</p>
						<p class="tc">审核中</p>
					</section>
				</section>
				</section>	
			<!-- 有工位reject -->
				<section id="chunkReject">
						<section class="common_bg">
					<section class="perfect pd">
						<p class="form-inpt-p">
							<label  >租金</label>
							<input  type="text"  name="sumRental" class="inpt sumRental"  required type="text" readonly="readonly" />(元/月)
						</p>
						<p class="form-inpt-p">
							<label >租用开始时间</label>
      						<input type="text" name="stratTime" id="stratTime" required class="inpt stratTime"  readonly="readonly"/>
						</p>
						<p class="form-inpt-p">
							<label >租长时间(个月)</label>
      						<input type="text" name="monthNumber"  required class="inpt monthNumber"  readonly="readonly"/>
						</p>
						<p class="form-inpt-p">
							<span>租用结束时间</span>
							<input  name="endTime" class="inpt endTime" required  type="text"  readonly="readonly" />
						</p>
						<p class="tc"><label >审核失败:</label><label id="stationRemark"></label>
						<input type="button" class="btn rent_submmit2" onClick="gotoAgainApplyPage()" value="重新申请">
						</p>
					</section>
				</section>
				</section>	
			<!-- 有newly工位wait -->
				<section id="chunkNewlyWait">
						<section class="common_bg">
					<section class="perfect pd">
						<p class="form-inpt-p">
							<label  >租金</label>
							<input  type="text"  name="sumRental" class="inpt sumRental"  required type="text" readonly="readonly" />(元/月)
						</p>
						<p class="form-inpt-p">
							<label >租用开始时间</label>
							<input  name="stratTime" class="inpt stratTime" required  type="text"  readonly="readonly" />
						</p>
						<p class="form-inpt-p">
							<span>租用结束时间</span>
							<input name="endTime" class="inpt endTime" required  type="text"  readonly="readonly" />
						</p>
							<p class="tc">（结束时间与您第一批工位租用时间一致）</p>
							<p class="tc">审核中</p>
					</section>
				</section>
				</section>	
			<!-- 有newly工位reject -->
				<section id="chunkNewlyReject">
					<section class="common_bg">
						<section class="perfect pd">
						<p class="form-inpt-p">
							<label >租金</label>
							<input  type="text"  name="sumRental" class="inpt sumRental"  required type="text" readonly="readonly" />(元/月)
						</p>
						<p class="form-inpt-p">
							<label >租用开始时间</label>
      						<input type="text" name="stratTime"  required class="inpt stratTime"  readonly="readonly"/>
						</p>
						<p class="form-inpt-p">
							<span>租用结束时间</span>
							<input  name="endTime" class="inpt endTime" required  type="text"  readonly="readonly" />
						</p>
							<p class="tc">（结束时间与您第一批工位租用时间一致）</p>
							<p class="tc"><label >审核失败:</label><label id="stationRemark"></label></p>
							<p class="tc"><input type="button" class="btn rent_submmit2" onClick="gotoAgainApplyPage()" value="重新申请"></p>
						</section>
					</section>
				</section>	
			</section>
			<!-- 有change工位wait -->
			<section id="chunkChangeWait" class="mt">
				<section class="common_bg">
					<section class="perfect pd">
						<p class="form-inpt-p">
							<span>租用结束时间</span>
							<input  name="endTime" class="inpt endTime" required  type="text"  readonly="readonly" />
						</p>
						<p class="tc">审核中</p>
					</section>
				</section>
			</section>		
			<!-- 有change工位reject -->
			<section id="chunkChangeReject" class="mt">
				<section class="common_bg">
					<section class="perfect pd">
						<p class="form-inpt-p">
							<span>租用结束时间</span>
							<input  name="endTime" class="inpt endTime" required  type="text"  readonly="readonly" />
						</p>
					</section>
				</section>
				<p class="tc"><label >审核失败:</label><label id="stationRemark"></label></p>
				<p class="tc"><input type="button" class="btn rent_submmit2" onClick="gotoAgainApplyPage()" value="重新申请"></p>
			</section>		
		</section>
	<script src="js/jquery.min.js"></script>
	<script src="js/main.js"></script>
	<script src="js/responsive.js"></script>
	<script type="text/javascript">
		var index;
		var myEndTime;
		var endTime;
		var myStratTime;
		var stratTime;
		var monthNumber;
		var stationRemark;
		var sumRental;
		var leaseId;
		var momentStationIds;
		$(function(){
			$("#table2").hide();
			$("#chunkNothing").hide();
			$("#changeStation").hide();
			$("#chunkPass").hide();
			$("#chunkWait").hide();
			$("#chunkReject").hide();
			$("#chunkNewlyWait").hide();
			$("#chunkNewlyReject").hide();
			$("#chunkChangeWait").hide();
			$("#chunkChangeReject").hide();
			url="api/resourecLease/queryisExistStation";
			$.post(url,function(data){
				 if(data.response==null){
					 $("#chunkNothing").show();
				}else{
					$("#table2").show();
					var time=0;
					var faglePass=false;
					var fagleWait=false;
					var fagleReject=false;
					var fagleNewlyWait=false;
					var fagleNewlyReject=false;
					var fagleChangeWait=false;
					var fagleChangeReject=false;
					for(i=0;i<data.response.length;i++){
						if(data.response[i].newlyStuats==0&&data.response[i].status==1){
							faglePass=true;
							endTime=data.response[i].endTime;
							monthNumber=data.response[i].monthNumber;
							stationRemark=data.response[i].stationRemark;
							stratTime=data.response[i].stratTime;
							sumRental=data.response[i].sumRental;
							leaseId=data.response[i].leaseId;
						}
						if(data.response[i].newlyStuats==0&&data.response[i].status==0){
							faglePass=false;
							fagleWait=true;
							endTime=data.response[i].endTime;
							monthNumber=data.response[i].monthNumber;
							stationRemark=data.response[i].stationRemark;
							stratTime=data.response[i].stratTime;
							sumRental=data.response[i].sumRental;
							leaseId=data.response[i].leaseId;
							break;
						}
						if(data.response[i].newlyStuats==0&&data.response[i].status==2){
							faglePass=false;
							fagleReject=true;
							endTime=data.response[i].endTime;
							monthNumber=data.response[i].monthNumber;
							stationRemark=data.response[i].stationRemark;
							stratTime=data.response[i].stratTime;
							sumRental=data.response[i].sumRental;
							leaseId=data.response[i].leaseId;
							momentStationIds=data.response[i].momentStationIds;
							break;
						}
						if(data.response[i].newlyStuats==1&&data.response[i].status==0){
							faglePass=false;
							fagleNewlyWait=true;
							endTime=data.response[i].endTime;
							monthNumber=data.response[i].monthNumber;
							stationRemark=data.response[i].stationRemark;
							stratTime=data.response[i].stratTime;
							sumRental=data.response[i].sumRental;
							leaseId=data.response[i].leaseId;
							break;
						}
						if(data.response[i].newlyStuats==1&&data.response[i].status==2){
							faglePass=false;
							fagleNewlyReject=true;
							endTime=data.response[i].endTime;
							monthNumber=data.response[i].monthNumber;
							stationRemark=data.response[i].stationRemark;
							stratTime=data.response[i].stratTime;
							sumRental=data.response[i].sumRental;
							leaseId=data.response[i].leaseId;
							momentStationIds=data.response[i].momentStationIds;
							break;
						}
						if(data.response[i].newlyStuats==1&&data.response[i].status==3){
							faglePass=false;
							fagleChangeWait=true;
							endTime=data.response[i].endTime;
							monthNumber=data.response[i].monthNumber;
							stationRemark=data.response[i].stationRemark;
							stratTime=data.response[i].stratTime;
							sumRental=data.response[i].sumRental;
							leaseId=data.response[i].leaseId;
							break;
						}
						if(data.response[i].newlyStuats==1&&data.response[i].status==4){
							faglePass=false;
							fagleChangeReject=true;
							endTime=data.response[i].endTime;
							monthNumber=data.response[i].monthNumber;
							stationRemark=data.response[i].stationRemark;
							stratTime=data.response[i].stratTime;
							sumRental=data.response[i].sumRental;
							leaseId=data.response[i].leaseId;
							momentStationIds=data.response[i].momentStationIds;
							break;
						}
					}
					if(fagleWait){
						$("#chunkWait").show();
						stationImg(0,0,3);
					}else if(fagleReject){
						$("#chunkReject").show();
						stationImgReject(1,2,3,momentStationIds);
					}else if(fagleNewlyWait){
						$("#chunkNewlyWait").show();
						stationImg(1,0,3);
					}else if(fagleNewlyReject){
						$("#chunkNewlyReject").show();
						stationImgReject(1,2,3,momentStationIds);
					}else if(fagleChangeWait){
						$("#chunkChangeWait").show();
						$("#changeStation").show();
						changeStationImg(1,3);
					}else if(fagleChangeReject){
						$("#chunkChangeReject").show();
						$("#changeStation").show();
						changeRejectStationImg();
					}else if(faglePass){
						$("#chunkPass").show();
						stationImg(0,-1,1);
					}
					var date=new Date(endTime);
					var year=date.getFullYear();
					var month=date.getMonth();
					var day=date.getDate();
					var b=day+"";
					var a=month+"";
					if(a.length==1){
						month="0"+month;
					}
					if(b.length==1){
						day="0"+day;
					}
					myEndTime=year+"-"+month+"-"+day;
					$(".endTime").each(function(){
						$(this).val(myEndTime);
					});
					
					var date=new Date(stratTime);
					var year=date.getFullYear();
					var month=date.getMonth();
					var day=date.getDate();
					var b=day+"";
					var a=month+"";
					if(a.length==1){
						month="0"+month;
					}
					if(b.length==1){
						day="0"+day;
					}
					myStratTime=year+"-"+month+"-"+day;
					$(".stratTime").each(function(){
						$(this).val(myStratTime);
					});
					setTimeout(function(){
						$(".sumRental").each(function(){
							$(this).val(sumRental);
						});
						$(".monthNumber").each(function(){
							$(this).val(monthNumber);
						});
						$(".leaseId").each(function(){
							$(this).val(leaseId);
						});
						$(".stationRemark").each(function(){
							$(this).val(stationRemark);
						});
					}, 200);
				}
			});
		});	
		
		var stationImg=function(newlyStatus,status,stationStatus){
				$(function(){
					var reqdate={
							"newlyStatus":newlyStatus,
							"status":status,
							"stationStatus":stationStatus
						}
					$.post("api/resourecLease/stationImg",reqdate, function(data){
							if(data.code!=0){
								return;
								}
							var	stations=data.response.listS;
							var req=data.response.listAllS;
							if(req.length>0){
								var b=parseInt(req[0].totalLines);
								var a=parseInt(req[0].totalRows);
							$('#table1').empty();
							for(i=0;i<b;i++){
							$('#table1').append("<tr id='tr"+i+"'></tr>");
							for(j=0;j<a;j++){
									var fagle=false;
									if(stations=="nonentity"){
										fagle=false;
									}else{
										for(d=0;d<stations.length;d++){
											if(req[(i*a)+j].name==stations[d].name){
												fagle=true;
												break;
											}
										}
									}
									if(req[(i*a)+j].state!=0){
											if(fagle){
													var f="s"+i+j;
													var val=name+i+j+","+i+","+j;
													$("#tr"+i).append("<td id='td"+f+"'>"+req[(i*a)+j].name+"</td>");
													$("#td"+f).css("background","red");
											}else{
												$("#tr"+i).append("<td id= td"+req[(i*a)+j].name+" class='occupy' >"+req[(i*a)+j].name+"</td>");
											}
											}else{
														var f="s"+i+j;
														var val=name+i+j+","+i+","+j;
														$("#tr"+i).append("<td id='td"+f+"'>"+req[(i*a)+j].name+"</td>");
											}
										}
									}
								}
							});
			});
			}
		//生成工位改变工位表
		var changeStationImg=function(newlyStatus,status){
				$(function(){
					var reqdate={
							"newlyStatus":newlyStatus,
							"status":status,
						}
					$.post("api/resourecLease/changeStationImg",reqdate, function(data){
							if(data.code!=0){
								return;
								}
							var	stations=data.response.listS;
							var req=data.response.listAllS;
							var changeStations=data.response.listSC;
							if(req.length>0){
								var b=parseInt(req[0].totalLines);
								var a=parseInt(req[0].totalRows);
							$('#table1').empty();
							for(i=0;i<b;i++){
							$('#table1').append("<tr id='tr"+i+"'></tr>");
							for(j=0;j<a;j++){
									var fagle=false;
									var fagle1=false;
									if(stations.length<=0){
										fagle=false;
									}else{
										for(d=0;d<stations.length;d++){
											if(req[(i*a)+j].name==stations[d].name){
												fagle=true;
												break;
											}
										}
									}
									for(d=0;d<changeStations.length;d++){
											if(req[(i*a)+j].name==changeStations[d].name){
												fagle1=true;
												break;
											}
										}
									if(req[(i*a)+j].state!=0){
										if(fagle1){
											var f="s"+i+j;
											var val=name+i+j+","+i+","+j;
											$("#tr"+i).append("<td id='td"+f+"'>"+req[(i*a)+j].name+"</td>");
											$("#td"+f).css("background","#00E19F");
										}else
											if(fagle){
													var f="s"+i+j;
													var val=name+i+j+","+i+","+j;
													$("#tr"+i).append("<td id='td"+f+"'>"+req[(i*a)+j].name+"</td>");
													$("#td"+f).css("background","red");
											}else{
												$("#tr"+i).append("<td id= td"+req[(i*a)+j].name+" class='occupy' >"+req[(i*a)+j].name+"</td>");
											}
											}else{	
												var f="s"+i+j;
												var val=name+i+j+","+i+","+j;
												$("#tr"+i).append("<td id='td"+f+"'>"+req[(i*a)+j].name+"</td>");
											}
										}
									}
								}
							});
			});
			}
		//生成工位改变Reject工位表
		var changeRejectStationImg=function(){
				$(function(){
					$.post("api/resourecLease/changeRejectStationImg", function(data){
							if(data.code!=0){
								return;
								}
							var	stations=data.response.listS;
							var req=data.response.listAllS;
							var changeStations=data.response.listSC;
							if(req.length>0){
								var b=parseInt(req[0].totalLines);
								var a=parseInt(req[0].totalRows);
							$('#table1').empty();
							for(i=0;i<b;i++){
							$('#table1').append("<tr id='tr"+i+"'></tr>");
							for(j=0;j<a;j++){
									var fagle=false;
									var fagle1=false;
									if(stations.length<=0){
										fagle=false;
									}else{
										for(d=0;d<stations.length;d++){
											if(req[(i*a)+j].name==stations[d].name){
												fagle=true;
												break;
											}
										}
									}
									for(d=0;d<changeStations.length;d++){
											if(req[(i*a)+j].name==changeStations[d].name){
												fagle1=true;
												break;
											}
										}
									if(req[(i*a)+j].state!=0){
										if(fagle1){
											var f="s"+i+j;
											var val=name+i+j+","+i+","+j;
											$("#tr"+i).append("<td id='td"+f+"'>"+req[(i*a)+j].name+"</td>");
											$("#td"+f).css("background","red");
										}else
											if(fagle){
													var f="s"+i+j;
													var val=name+i+j+","+i+","+j;
													$("#tr"+i).append("<td id='td"+f+"'>"+req[(i*a)+j].name+"</td>");
													$("#td"+f).css("background","#00E19F");
											}else{
												$("#tr"+i).append("<td id= td"+req[(i*a)+j].name+" class='occupy' >"+req[(i*a)+j].name+"</td>");
											}
											}else{	
												var f="s"+i+j;
												var val=name+i+j+","+i+","+j;
												$("#tr"+i).append("<td id='td"+f+"'>"+req[(i*a)+j].name+"</td>");
											}
										}
									}
								}
							});
			});
			}
			
			var stationImgReject=function(newlyStatus,status,stationStatus,momentStationIds){
				$(function(){
					var reqdate={
							"newlyStatus":newlyStatus,
							"status":status,
							"stationStatus":stationStatus
						}
					
					$.post("api/resourecLease/stationImg",reqdate, function(data){
							if(data.code!=0){
								return;
								}
								var reqdate2={
										"momentStationIds":momentStationIds
								}
								$.post("api/resourecStation/queryByStationIds",reqdate2, function(data2){
									if(data2.code!=0){
										return;
										}
							var	stations=data2.response;
								
							var req=data.response.listAllS;
							if(req.length>0){
								var b=parseInt(req[0].totalLines);
								var a=parseInt(req[0].totalRows);
							$('#table1').empty();
							for(i=0;i<b;i++){
							$('#table1').append("<tr id='tr"+i+"'></tr>");
							for(j=0;j<a;j++){
									var fagle=false;
									if(stations.length<=0){
										fagle=false;
										
									}else{
										for(d=0;d<stations.length;d++){
											
											if(req[(i*a)+j].name==stations[d].name){
												fagle=true;
												break;
											}
										}
									}
									
									if(req[(i*a)+j].state!=0){
												$("#tr"+i).append("<td id= td"+req[(i*a)+j].name+" class='occupy' >"+req[(i*a)+j].name+"</td>");
											}else{
												if(fagle){
													var f="s"+i+j;
													var val=name+i+j+","+i+","+j;
													$("#tr"+i).append("<td id='td"+f+"'>"+req[(i*a)+j].name+"</td>");
													$("#td"+f).css("background","red");
												}else{
														var f="s"+i+j;
														var val=name+i+j+","+i+","+j;
														$("#tr"+i).append("<td id='td"+f+"'>"+req[(i*a)+j].name+"</td>");
													}
											}
										}
									}
								}  
								});
							});
			});
			}
			var gotoAgainApplyPage=function(){
				var reqdata={
						"leaseId":leaseId
				};
				$.post("api/resourecLease/againApply",reqdata,function(data){
					alert("重新申请工位");
					window.location.href="mystation.jsp";
				});
			}
			var gotoApplyPage=function(){
				window.location.href="mystationapply.jsp";
			}
			var gotoNewlyApplyPage=function(){
				window.location.href="mynewlystationapply.jsp?endTime="+myEndTime;
			}
			var gotoChangeApplyPage=function(){
				window.location.href="mystationchangeapply.jsp?endTime="+myEndTime;
			}
	</script>
	</body>
</html>
